btrfs receive: add --fsync and --syncfs options#1110
Closed
mge-fbe-com wants to merge 1 commit intokdave:develfrom
Closed
btrfs receive: add --fsync and --syncfs options#1110mge-fbe-com wants to merge 1 commit intokdave:develfrom
mge-fbe-com wants to merge 1 commit intokdave:develfrom
Conversation
Add --fsync flag that fsyncs each file before closing during receive, ensuring data is persisted and detecting async IO errors early. Add --syncfs flag that calls syncfs() on the destination filesystem after receiving, syncing all data in a single operation at the end. Signed-off-by: Michal Grzedzicki <mge@meta.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Encoded writes were silently ignoring write errors. This is fixed on the kernel side in https://lore.kernel.org/lkml/20260330160644.3678224-1-mge@meta.com/. This change augments that fix with optional fsync/syncfs support so users can enable strict checks on data write durability.
New flags:
--fsync— fsyncs each file before closing during receive, ensuring data is persisted and detecting async I/O errors early at the individual file level. Higher I/O overhead but pinpoints the exact file that failed.--syncfs— callssyncfs()on the destination filesystem after receiving, catching any remaining unflushed writeback errors in a single operation. Lower overhead but only reports errors at the end.Both flags require the kernel-side fix to be effective — on unfixed kernels, encoded write errors are silently dropped and never flagged, so neither
fsyncnorsyncfswill detect them.Test plan
Tested with a dm-flakey device returning write errors after 100MB offset on a 2GB device on a kernel with the fix.
Without flags — error is only caught late, at the final
BTRFS_IOC_SET_RECEIVED_SUBVOLioctl:=== Test: no sync flags ===
At subvol volume
ERROR: ioctl BTRFS_IOC_SET_RECEIVED_SUBVOL failed: Input/output error
With
--syncfs— same late error, plussyncfsalso reports the failure:=== Test: with --syncfs ===
At subvol volume
ERROR: ioctl BTRFS_IOC_SET_RECEIVED_SUBVOL failed: Input/output error
ERROR: syncfs on destination failed: Input/output error
With
--fsync— error is caught early at the specific file that failed:=== Test: with --fsync ===
At subvol volume
ERROR: fsync on /tmp/flakey-mnt//volume/.meta/private/opts/artifacts_may_require_repo failed: Input/output error
Test script (dm-flakey setup)